#ifndef HEADER_H
#define HEADER_H

//PDP-8 datapath
unsigned short fetch();
int decode(unsigned short inst);

//initialzation
int initialize(void);
int readobj(char[]);

//utility & debug
int displaystatistics();
int displaymemory(int);
int displayregs(int);
int updateExtraMemCyc(unsigned short inst);  	//tony
int createTrace(int, unsigned short inst);		//jinho
int initiatetrace();

//Effective address calculation & Memory read/write
unsigned short calEAddr(unsigned short inst);	//jinho
unsigned short readMEM(unsigned short);
unsigned short writeMEM(unsigned short, unsigned short);

//MRI instructions
int AND(unsigned short inst);		//tony
int TAD(unsigned short inst);		//tony
int ISZ(unsigned short inst);		//tony
int DCA(unsigned short inst);		//tony
int JMS(unsigned short inst);		//tony
int JMP(unsigned short inst);		//tony

//IO INSTRUCTION stubs only + count increment
int IO(unsigned short inst);		//tony

//MICRO INSTRUCTIONS
int opcode7(unsigned short inst); //increment cycle by 1  //jinho

//Group 1
int NOP(unsigned short inst);			//jinho
int CLA(unsigned short inst);			//jinho
int CLL(unsigned short inst);			//jinho
int CMA(unsigned short inst);			//jinho
int CML(unsigned short inst);
int IAC(unsigned short inst);			//jinho
int RAR(unsigned short inst);			//albert
int RTR(unsigned short inst);			//albert
int RAL(unsigned short inst);			//albert
int RTL(unsigned short inst);		 	//albert

//Group 2
int SMA(unsigned short inst);			//hoa
int SZA(unsigned short inst);			//hoa
int SNL(unsigned short inst);			//hoa

 //Group 2 OR subgroup combination
int SMASZA(unsigned short inst);
int SMASNL(unsigned short inst);
int SZASNL(unsigned short inst);
int SMASZASNL(unsigned short inst);

int SPA(unsigned short inst);			//hoa
int SNA(unsigned short inst);			//hoa
int SZL(unsigned short inst);			//hoa

 //Group 2 AND subgroup combination
int SPASZL(unsigned short inst);
int SPASNA(unsigned short inst);
int SNASZL(unsigned short inst);
int SPASNASZL(unsigned short inst);

 //Group 2 Other
int SKP(unsigned short inst);			//hoa
int CLA(unsigned short inst);			//hoa
int OSR(unsigned short inst);			//hoa
int HLT(unsigned short inst);			//hoa


 //Group 3  STUBS only
int CLA(unsigned short inst);			//albert
int MQL(unsigned short inst);			//albert
int MQA(unsigned short inst);			//albert
int SWP(unsigned short inst);			//albert
int CAM(unsigned short inst);			//albert

//IO
// Input
int KCF(void); // 0 Keyboard Clear Flags -  (PDP-8/E)
int KSF(void); // 1 Keyboard Skip if Flag - If KF=1 (input data ready), next instruction skipped
int KCC(void); // 2 Keyboard Clear and read character clear - KF reset, AC cleared, reading initialized
int KRS(void); // 4 Keyboard Read Static - OR KF_KB[4:11] with AC
int KIE(void); // 5 Keyboard Interrupt Enable - AC loaded to DCR (PDP-8/E) interrupt enable and status eanble
int KRB(void); // 6 Keyboard Read and begin next read - KF_KB[4:11] -> AC, KF cleared (KCC -> KRS)

// Output
int TFL(void); // 0 Teleprinter Flag set - TF set (output data ready) (PDP-8/E)
int TSF(void); // 1 If TF set, skip next instruction (ALL)
int TCF(void); // 2 Teleprinter Clear Flag - Reset TF (ALL)
int TPC(void); // 4 Teleprinter Print Character- AC[4:11] -> TB (ALL)
int TSK(void); // 5 Teleprinter Skip - If KF or TF set, skip next instruction (PDP-8/E)
int TLS(void); // 6 Teleprinter Load and start - AC[4:11] -> TB (ALL), initiating output, reset TF (TCF+TPC)

//Global variables declaration
extern unsigned short memory[4096];

//PDP-8 registers
extern unsigned short LB_AC;
extern unsigned short MQ;
extern unsigned short PC;
extern unsigned short IR;
extern unsigned short MB;
extern unsigned short CPMA;
extern unsigned short SR;

extern unsigned short KF_KB;	//Keyboard Buffer
extern unsigned short TF_TB;	//Teleprinter Buffer


//instruction stored
//extern unsigned short inst;

//counters
extern int ANDcount;
extern int TADcount;
extern int ISZcount;
extern int DCAcount;
extern int JMScount;
extern int JMPcount;
extern int IOcount;
extern int microcount;
extern int totalInst;
extern int extraMemCycCount;
extern int totalCycCount;
extern int memWriteCount;
extern int memReadCount;

extern int debug;
extern int debugparam;
extern int debugfile;

extern char objFilePath[];

// Used to make trace file.
#define READ 0
#define WRITE 1
#define FETCH 2

// Debug parameters
#define DEBUG		1
#define DEBUGPARAM	1
#define DEBUGFILE	0

#endif 
